package com.wll.thread.demo;

import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 * @Description: 自己创建线程池
 * @Author: Wanglulu
 * @Date: 2021/4/29 11:18
 * @Version 0.0.1
 */
public class ThreadPool {
    /**
     * 线程池的基本大小
     */
    static int corePoolSize = 5;
    /**
     * 线程池最大数量
     */
    static int maximumPoolSizeSize = 10;
    /**
     * 线程活动保持时间
     */
    static long keepAliveTime = 1;
    /**
     * 任务队列
     */
    static ArrayBlockingQueue workQueue = new ArrayBlockingQueue(10);

    public static ThreadPoolExecutor createThead(int size) {
        if (size < 0 || size > 10) {
            size = corePoolSize;
        }
        ThreadPoolExecutor executor = new ThreadPoolExecutor(
                size,
                maximumPoolSizeSize,
                keepAliveTime,
                TimeUnit.SECONDS,
                workQueue);
        return executor;
    }
}
